/*
分别对于同步日志器&异步日志器进行各自的性能测试
    - 单写日志线程的性能
    - 多写日志线程的性能
实现:
    封装一个接口(日志器名称, 线程数量, 日志数量, 单条日志大小)

每秒输出量=日志数量/总耗时
每秒输出大小=日志数量*单条日志大小/总耗时
*/
#include "../logs/log.h"
#include "bench.h"

void sync_bench(size_t thread_num, size_t msg_cnt, size_t msg_len)
{
    std::string logger_name="sync_logger";
    std::unique_ptr<LOG::LoggerBuilder> builder(new LOG::GlobalLoggerBuilder());
    builder->buildLoggerName(logger_name);
    builder->buildLoggerFormat("[%c][%f:%l][%p]%m%n");
    builder->buildLoggerType(LOG::LoggerType::LOGGER_SYNC);
    builder->buildSink<LOG::FileSink>("./logfile/sync.log");
    builder->build();
    printf("同步日志测试: %d threads, %d messages\n", (int)thread_num, (int)msg_cnt);
    LOG::bench(logger_name, thread_num, msg_len, msg_cnt);
}
void async_bench(size_t thread_num, size_t msg_cnt, size_t msg_len)
{
    std::string logger_name="async_logger";
    std::unique_ptr<LOG::LoggerBuilder> builder(new LOG::GlobalLoggerBuilder());
    builder->buildLoggerName(logger_name);
    builder->buildLoggerFormat("[%c][%f:%l][%p]%m%n");
    builder->buildLoggerType(LOG::LoggerType::LOGGER_ASYNC);
    builder->buildEnableUnSafeAsync();
    builder->buildSink<LOG::FileSink>("./logfile/async.log");
    builder->build();
    printf("异步日志测试: %d threads, %d messages\n", (int)thread_num, (int)msg_cnt);
    LOG::bench(logger_name, thread_num, msg_len, msg_cnt);
}

void bench_test()
{
    /*异步日志输出*/
    async_bench(1, 1000000, 100);
    async_bench(5, 1000000, 100);
    // 同步写日志
    sync_bench(1, 1000000, 100);
    sync_bench(5, 1000000, 100);
}

int main(int argc, char *argv[])
{
    bench_test();

    return 0;
}